﻿var subjectList = {
    gridDefine: {
        toolbar: { items: [{ text: lang.add, click: function () { openPage("themeEdit", "", "", lang.add); }, icon: 'add'}] },
        columns: [

            { display: lang.subjectName, name: 'SUBJ_NAME', minWidth: 120 },
            { display: lang.PRORITY, name: 'PRORITY', minWidth: 80 },
            { display: lang.MATCH, name: 'MATCH', minWidth: 100, render: LinkMatch },
            { display: lang.SUBJ_CLASS_NAME, name: 'SUBJ_CLASS_NAME', minWidth: 100 },
            { display: lang.KEYW, name: 'KEYW', minWidth: 220 },
            //{ display: lang.EXT_CONT, name: 'EXT_CONT', minWidth: 220 },
            { display: lang.searchSql, name: 'WHERE_FMT', minWidth: 220 },
            { display: lang.operation, name: 'DICTTYPE_ID2', minWidth: 180, align: 'center', render: linkop }
        ],
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QuerySubjectList"
    },
    init: function () {
        jsPageRender(this, true);
    },
    search: function () {
        jsPageSearch(this);
    }
};
function LinkMatch(value, row, index) {
    if (row.MATCH == '1') { return lang.key_word_match; }
    else if (row.MATCH == '2') { return lang.table_field_match; }
    else { return lang.complete_match; }
}

function linkop(value, row, index) {
    var _str = 'dicttypeid=' + row.SUBJ_ID;
    return '<span style="padding-right:15px;"><a href="javascript:void(0)" onclick="openPage(\'themeEdit\',\'' + _str + '\');">' + lang.edit + '</a></span><span style="padding-right:15px;"><a href="javascript:void(0)" onclick="deletedicttype(\'' + row.SUBJ_ID + '\',\'' + row.SUBJ_NAME + '\');">' + lang.delete_ + '</a></span>';
}

function deletedicttype(dicttypeid, SUBJ_NAME) {
    $.extend($.messager.defaults, {
        ok: lang.ok,
        cancel: lang.cancel
    });
    $.confirm(lang.sure_to_delete_the_current_theme + "[" + SUBJ_NAME + "]", lang.delete_type, function (b) {
        if (b) {
            $.ajaxHandler({
                url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
                urlType: "deleteSub",
                model: function () { return $.toJSON({ 'action': 0, 'SUBJ_ID': dicttypeid }); },
                success: function (data) {
                    $.alert(lang.Successfully_deleted, null, function () { subjectList.search(); });
                }
            });
        }
    });
}